package com.biz;

import java.util.ArrayList;
import java.util.Calendar;

import com.dao.OrderDAO;
import com.entity.Beer;
import com.entity.Member;
import com.entity.Order;

public class OrderBiz {
	
	public int insert(Member mem, Beer beer, int quantity){
		OrderDAO dao = new OrderDAO();
		Calendar cal = Calendar.getInstance();
		int day = cal.get(Calendar.DAY_OF_MONTH);
		int h = cal.get(Calendar.HOUR);
		int m = cal.get(Calendar.MINUTE);
		int s = cal.get(Calendar.SECOND);
		String mid = mem.getId().substring(0, 2);
		String bno = beer.getBno().substring(0, 2);
		String o_no = String.format("%s%s%02d%02d%02d%02d", mid, bno ,day,h,m,s);
		return dao.insert(o_no, mem.getId(), beer.getBno(), quantity);
	}
	
	public ArrayList<Order> select(){
		OrderDAO dao = new OrderDAO();
		return dao.select();
	}
	
	public ArrayList<Order> selectMyOrderList(String id){
		OrderDAO dao = new OrderDAO();
		return dao.selectMyOrderList(id);
	}

	public int delete(String o_no){
		OrderDAO dao = new OrderDAO();
		return dao.delete(o_no);
	}
}
